namespace etcetera.Mvc.UI.Toolbar
{
    public class ToolbarPageStatus : ToolbarItem
    {
        public override string GetValue()
        {
            string val = string.Format("<div class='{0}'>", "tCtrl");

            PagerToolStrip toolStrip = (PagerToolStrip)Toolbar.ToolStrip;

            int nFrom = (toolStrip.CurrentPage - 1) * toolStrip.PageSize + 1;
            int nTo = nFrom + toolStrip.PageSize - 1;
            if (nTo > toolStrip.TotalItemCount)
                nTo = toolStrip.TotalItemCount;

            if (toolStrip.PageSize >= toolStrip.TotalItemCount)
            {
                // Showing {0} of {0}
                val += string.Format("<span class='{0}'>{1}</span>", "tBtnST", toolStrip.SinglePageFormatText);
                val = string.Format(val, toolStrip.TotalItemCount);
            }
            else
            {
                // Showing {0} to {1} of {2}, eg. Showing 31 to 40 of 65
                val += string.Format("<span class='{0}'>{1}</span>", "tBtnST", toolStrip.FormatText);
                val = string.Format(val, nFrom, nTo, toolStrip.TotalItemCount);
            }

            val += "</div>";

            return val;
        }
    }
}